package cn.tedu.csmall.product.config;

import lombok.extern.slf4j.Slf4j;
import org.hibernate.validator.HibernateValidator;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

import javax.validation.Validation;

/**
 * Spring Validation的验证配置类
 *
 * @author admin
 * @date 2022/09/30
 */
@Slf4j
@Configuration
public class ValidationConfiguration {
    public ValidationConfiguration() {
        log.debug("创建配置类：ValidationConfiguration");
    }

    /**
     * 验证器
     *
     * @return {@link javax.validation.Validator}
     */
    @Bean
    public javax.validation.Validator validator() {
        return Validation.byProvider(HibernateValidator.class)
                .configure()//开始配置Validator
                .failFast(true)    //快速失败，及检查请求参数发现错误时直接是为失败，并不像后继续检查
                .buildValidatorFactory()
                .getValidator();
    }
}
